package com.sample.base.ui.fragment.recyclerview

import android.os.Bundle
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import androidx.databinding.DataBindingUtil
import com.sample.base.R
import com.sample.base.adapter.Adapter2222
import com.sample.base.databinding.FragmentRecyclerClickBinding
import com.sample.base.ui.fragment.BaseFragment

class RecyclerClickFragment : BaseFragment() {
    private var _binding: FragmentRecyclerClickBinding? = null
    private val binding get() = _binding!!

    override fun inflaterView(inflater: LayoutInflater, container: ViewGroup?): View {
        // _binding = FragmentClickBinding.inflate(inflater, container, false)
        _binding = DataBindingUtil.inflate(inflater, R.layout.fragment_recycler_click, container, false)
        return binding.root
    }

    override fun afterOnCreate() {
        val list1 = listOf("1", "3", "5", "7", "9")
        val adapter1 = Adapter2222(list1)
        adapter1.setOnItemClickListener { adapter, _, position, _ ->
            val item = adapter.getItem(position)
            showToast("adapter1-itemClick:$item")
        }
        binding.adapter1 = adapter1
        val list2 = listOf("2", "4", "6", "8", "10")
        val adapter2 = Adapter2222(list2)
        adapter2.setOnItemClickListener { adapter, _, position, _ ->
            val item = adapter.getItem(position)
            showToast("adapter2-itemClick:$item")
        }
        binding.adapter2 = adapter2
    }

    companion object {
        private const val ARG_PARAM1 = "param1"
        fun newInstance(param1: String? = ""): RecyclerClickFragment {
            val fragment = RecyclerClickFragment()
            val args = Bundle()
            args.putString(ARG_PARAM1, param1)
            fragment.arguments = args
            return fragment
        }
    }

    override fun unbind() {
        super.unbind()
        _binding = null
    }
}